import { Component} from 'react';
import React from 'react'
import { Carousel, WingBlank } from 'antd-mobile';
import API from '../untils/api'
class SwiperSlider extends Component {
    constructor(){
        super();
        this.state = {
            data: [],
            imgHeight: 250,

        }
    }
    render() {
        return (
            <div className="banner">
                <WingBlank>
                    <Carousel
                        infinite={true}
                        beforeChange={(from, to) => console.log(`slide from ${from} to ${to}`)}
                        afterChange={index => console.log('slide to', index)}
                        autoplay={true}
                        autoplayInterval={2000}
                    >
                        {this.state.data.map((item,index) => (
                            <a
                                key={item.id}
                                href={item.link}
                                style={{ display: 'inline-block', width: '100%',height:this.state.imgHeight }}
                            >
                                <img
                                    src={item.img}
                                    alt=""
                                    style={{ width: '100%', verticalAlign: 'top' }}
                                    onLoad={() => {
                                        // fire window resize event to change height
                                        window.dispatchEvent(new Event('resize'));
                                        // this.setState({ imgHeight: 'auto' });
                                    }}
                                />
                            </a>
                        ))}
                    </Carousel>
                </WingBlank>
            </div>

        )
    }
    componentDidMount() {
        // simulate img loading
        let params={
            url:'/huoban-sales/http/sales/function/banner/findList.do',
            data:{
                title:'',
                currentPage:1
            }

        };
        API.request(params).then((res)=>{
           setTimeout(()=>{
               this.setState({
                   data: res.data.list
               });
           },200)
        });

    }
}


export default SwiperSlider